home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 66
/
Vol 66.iso
/
games
/
bob_espo.swf
/
scripts
/
__Packages
/
MiniGames
/
BaseMiniGame.as
Wrap
Text File
|
2013-04-24
|
4KB
|
161 lines
class MiniGames.BaseMiniGame extends State
{
static var sSTATE_HOWTOPLAY_IN = "HowToPlayIn";
static var sSTATE_HOWTOPLAY_IDLE = "HowToPlayIdle";
static var sSTATE_HOWTOPLAY_OUT = "HowToPlayOut";
static var sSTATE_MINIGAME = "MiniGame";
static var sSTATE_VICTORY = "Victory";
static var nSCORE_MAX = 1200;
static var nWAITING_TIME = 105;
function BaseMiniGame(_mcRef)
{
super(_mcRef);
this.bOver = false;
}
function initMiniGame()
{
}
function validateEndMiniGame()
{
}
function destroyMiniGame(_bQuitting)
{
if(_bQuitting == false || _bQuitting == undefined)
{
this.calculateScore();
}
this.cleanUp();
}
function calculateScore()
{
}
function addScoreFromTimeLeft(_nTimeMax, _nSecondsValue)
{
var _loc4_ = Math.round(_nTimeMax - this.nTime / Main.nFRAME_RATE);
if(_loc4_ < 0)
{
_loc4_ = 0;
}
_loc4_ *= _nSecondsValue;
if(_loc4_ > MiniGames.BaseMiniGame.nSCORE_MAX)
{
_loc4_ = MiniGames.BaseMiniGame.nSCORE_MAX;
}
CTRLGame.getRef().addToScore(_loc4_);
}
function isFinished()
{
return this.bOver;
}
function showInstructions()
{
this.setState(MiniGames.BaseMiniGame.sSTATE_HOWTOPLAY_IN);
Controller.getRef().getSounds().playSound("Minigame_HowToPlay_In",Controller.nSFX_VOLUME,1);
}
function doPause()
{
super.doPause();
}
function doUnPause()
{
super.doUnPause();
this.mcRef.stop();
}
function startGame()
{
this.clearSkipKeys();
this.setState(MiniGames.BaseMiniGame.sSTATE_MINIGAME);
CTRLGame.getRef().Screen.getInterface().unPauseTime();
this.initMiniGame();
this.nTime = 0;
}
function setVictory()
{
this.setState(MiniGames.BaseMiniGame.sSTATE_VICTORY);
CTRLGame.getRef().Screen.getInterface().pauseTime();
}
function pressKey()
{
if(Key.getCode() != Key.UP && (Key.getCode() != Key.DOWN && (Key.getCode() != Key.LEFT && (Key.getCode() != Key.RIGHT && this.sState == MiniGames.BaseMiniGame.sSTATE_HOWTOPLAY_IDLE))))
{
this.skipInstructions();
}
}
function pressMouseButton()
{
Controller.getRef().playClickSound();
this.skipInstructions();
}
function skipInstructions()
{
this.clearSkipKeys();
this.onOutInstructions();
}
function onOutInstructions()
{
this.setState(MiniGames.BaseMiniGame.sSTATE_HOWTOPLAY_OUT);
Controller.getRef().getSounds().playSound("Minigame_HowToPlay_Out",Controller.nSFX_VOLUME,1);
}
function clearSkipKeys()
{
delete this.mcRef.mcState.btnSkip.onRelease;
delete this.mcRef.mcState.btnSkip2.onRelease;
delete this.mcRef.mcState.btnSkip2.onRollOver;
this.mcRef.mcState.btnSkip.onRelease = undefined;
this.mcRef.mcState.btnSkip2.onRelease = undefined;
this.mcRef.mcState.btnSkip2.onRollOver = undefined;
if(this.oListener != null)
{
Key.removeListener(this.oListener);
delete this.oListener;
this.oListener = null;
}
}
function initSkipKeys()
{
this.oListener = new Object();
this.oListener.onKeyDown = Delegate.create(this,this.pressKey);
Key.addListener(this.oListener);
this.mcRef.mcState.btnSkip.onRelease = Delegate.create(this,this.skipInstructions);
this.mcRef.mcState.btnSkip2.onRollOver = Delegate.create(Main.getRef(),Main.getRef().rollOverButton);
this.mcRef.mcState.btnSkip2.onRelease = Delegate.create(this,this.pressMouseButton);
}
function HowToPlayIn()
{
if(this.stateFinished())
{
this.setState(MiniGames.BaseMiniGame.sSTATE_HOWTOPLAY_IDLE);
this.initSkipKeys();
}
}
function HowToPlayIdle()
{
if(this.stateFinished())
{
this.onOutInstructions();
}
}
function HowToPlayOut()
{
if(this.stateFinished())
{
this.startGame();
}
}
function MiniGame()
{
if(!Controller.getRef().isPaused())
{
this.nTime = this.nTime + 1;
this.validateEndMiniGame();
}
}
function Victory()
{
if(this.stateFinished())
{
this.bOver = true;
}
}
}